import { request } from '@/utils/request'
import type { ApiResponse } from '@/utils/request'

/**
 * 班级信息查询参数
 */
export interface ClassQuery {
  classCode?: string
  className?: string
  majorId?: number
  headteacherId?: number
  enrollmentYear?: number
  isActive?: boolean
  pageNum: number
  pageSize: number
}

/**
 * 班级信息表单数据
 */
export interface ClassForm {
  id?: number
  majorId: number
  majorName?: string
  classCode: string
  className: string
  enrollmentYear: number
  graduationYear?: number
  headteacherId?: number
  headteacherName?: string
  studentCount?: number
  classRoom?: string
  description?: string
  isActive?: boolean
}

/**
 * 班级信息详情
 */
export interface ClassInfo extends ClassForm {
  createdTime?: string
  updatedTime?: string
  createdBy?: number
  createdByName?: string
  updatedBy?: number
  updatedByName?: string
}

/**
 * 班级分页结果接口
 */
export interface ClassPageResult {
  records: ClassInfo[]
  total: number
  size: number
  current: number
  pages: number
}

/**
 * 获取班级列表
 * @param query 查询参数
 * @returns 分页结果
 */
export function listClass(query: ClassQuery) {
  return request.post<ApiResponse<ClassPageResult>>('/api/school/class/list', query)
}

/**
 * 获取班级详情
 * @param id 班级ID
 * @returns 班级详情
 */
export function getClass(id: number) {
  return request.get<ApiResponse<ClassInfo>>(`/api/school/class/${id}`)
}

/**
 * 新增班级
 * @param data 班级数据
 * @returns 新增结果
 */
export function addClass(data: ClassForm) {
  return request.post<ApiResponse<boolean>>('/api/school/class', data)
}

/**
 * 修改班级
 * @param data 班级数据
 * @returns 修改结果
 */
export function updateClass(data: ClassForm) {
  return request.put<ApiResponse<boolean>>('/api/school/class', data)
}

/**
 * 删除班级
 * @param id 班级ID
 * @returns 删除结果
 */
export function deleteClass(id: number) {
  return request.delete<ApiResponse<boolean>>(`/api/school/class/${id}`)
}

/**
 * 批量删除班级
 * @param ids 班级ID数组
 * @returns 批量删除结果
 */
export function batchDeleteClass(ids: number[]) {
  return request.delete<ApiResponse<boolean>>('/api/school/class/batch', ids)
}

/**
 * 获取班级状态选项
 * @returns 班级状态选项
 */
export function getClassStatusOptions() {
  return [
    {
      value: true,
      label: '启用'
    },
    {
      value: false,
      label: '禁用'
    }
  ]
} 